import java.util.*;
public class test {
    // 蓝桥杯 卡牌(⭐⭐⭐)
    public class Main {
        public static int n;
        public static long m;
        public static int[] a;
        public static int[] b;
        public static void main(String[] args){
            Scanner in = new Scanner(System.in);
            n = in.nextInt();
            m = in.nextLong();
            a = new int[n + 1];
            b = new int[n + 1];
            for(int i = 1;i <= n;i++){
                a[i] = in.nextInt();
            }
            for(int i = 1;i <= n;i++){
                b[i] = in.nextInt();
            }
            int l = 1;
            //a,b最大值为2n,最多能分4n套
            int r = 800010;
            while(l < r){
                int mid = l + (r - l + 1) / 2;
                if(check(mid) == 0){
                    r = mid - 1;
                }else {
                    l = mid;
                }
            }
            System.out.println(l);
        }
        public static int check(int mid){
            long sum = 0;
            for(int i = 1;i <= n;i++){
                // 足够,直接跳过
                if(a[i] >= mid) continue;
                // 如果(允许使用的空白牌数 不足以将牌凑到mid个,则失败)
                if(b[i] < mid - a[i]) return 0;
                sum += mid - a[i];
                if(sum > m) return 0;
            }
            return 1;
        }
    }
    // 蓝桥杯 求阶乘(⭐⭐)
    public static long k;
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        k = in.nextLong();
        long l = 1;
        long r = Long.MAX_VALUE;
        while(l < r){
            long mid = l + (r - l) / 2;
            if(check(mid) < k){
                l = mid + 1;
            }else {
                r = mid;
            }
        }
        System.out.println(check(l) == k ? l : -1);
    }
    public static long check(long mid){
        long sum = 0;
        while(mid != 0){
            sum += mid / 5;
            mid /= 5;
        }
        return sum;
    }
    // 蓝桥杯 冶炼金属
    public static int n;
    public static long[] a;
    public static long[] b;
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 普通金属O -> 特殊金属X
        // 转换率V
        // V(max) <= A / B (O/X)
        // V(min) >= A / (B + 1)
        n = in.nextInt();
        a = new long[n + 1];
        b = new long[n + 1];
        for(int i = 1;i <= n;i++){
            a[i] = in.nextLong();
            b[i] = in.nextLong();
        }
        // 寻找最大值
        long l = 1;
        long r = 1000000005;
        while(l < r){
            long mid = l + (r - l) / 2;
            if(checkMax(mid) == 0){
                l = mid + 1;
            }else {
                r = mid;
            }
        }
        long n1 = l;
        l = 1;r = 1000000005;
        while(l < r){
            long mid = l + (r - l) / 2;
            if(checkMin(mid) == 0){
                l = mid + 1;
            }else {
                r = mid;
            }
        }
        System.out.println(l + " " + n1);
    }
    //         25 26 29
    // 1 1 1 1  0  0  0
    public static long checkMax(long mid){
        for(int i = 1;i <= n;i++){
            if(a[i] / b[i] <= mid){
                return 1;
            }
        }
        return 0;
    }
    //16   18   19
    //0    0    0   1 1 1 1
    public static long checkMin(long mid){
        for(int i = 1;i <= n;i++){
            if(a[i] / (b[i] + 1) >= mid){
                return 0;
            }
        }
        return 1;
    }
}
